package bat.iog.hytool.config;

import java.io.*;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * peoperties文件的读写
 */
public class Config {
    private static final String configFile="common";

    /**
     * 通过key获取文件配置的value
     */
    public static String getConfigByKey(String key){
        ResourceBundle re = ResourceBundle.getBundle(configFile);
        return re.getString(key);
    }

    /**
     * 添加文件key-value值
     */
    public static void setConfigValue(String key, String value){
        Properties prop = new Properties();
        try {
            InputStream fis = new FileInputStream("/common.properties");
            prop.load(fis);
            OutputStream fos = new FileOutputStream("/common.properties");
            prop.setProperty(key, value);
            prop.store(fos, "Update "+key+ "value");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
